package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueService;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Autowired
    private TbClueMapper tbClueMapper;

    @Override //新增线索跟进记录
    public void add(ClueTrackRecordVo clueTrackRecordVo) {
        //补全跟进人
        clueTrackRecordVo.setCreateBy(SecurityUtils.getUsername());
        //补全本次跟进时间
        clueTrackRecordVo.setCreateTime(new Date());
        //补全类型[0正常跟进  1伪线索]
        clueTrackRecordVo.setType("0");
        //调用线索跟进表mapper保存
        tbClueTrackRecordMapper.add(clueTrackRecordVo);

       //调用线索表mapper更新
       TbClue tbClue = new TbClue();
       tbClue.setId(clueTrackRecordVo.getClueId());  //线索id
       tbClue.setAge(clueTrackRecordVo.getAge());   //用户年龄
       tbClue.setLevel(clueTrackRecordVo.getLevel()); //意向等级
       tbClue.setQq(clueTrackRecordVo.getQq());  //qq
       tbClue.setWeixin(clueTrackRecordVo.getWeixin());//微信
       tbClue.setSex(clueTrackRecordVo.getSex()); //性别
       tbClue.setSubject(clueTrackRecordVo.getSubject());//学科
       tbClue.setStatus(TbClue.StatusType.FOLLOWING.getValue());  //点击完跟进之后,状态要改变 [跟进中]
       //封装好后
       //调用线索表的更新就可以了,之前写过了mapper的更新,代码复用
       tbClueMapper.updateTbClue(tbClue);
    }


    //跟进记录回显(右边有分页)
    @Override
    public java.util.List<TbClueTrackRecord> findList(Long clueId) {
        //调用mapper查询数据库   把所有的信息记录都查询出来
        return tbClueTrackRecordMapper.findList(clueId);
    }

}
